package com.zjb.demo.common.exception;

import com.zjb.demo.common.constant.ExceptionCode;

/**
 * @author 庄佳彬
 * @since 2023/12/23 23:18
 */
public class AppException extends RuntimeException {

    private final ExceptionCode code;

    public AppException(ExceptionCode code) {
        super();
        this.code = code;
    }

    public AppException(ExceptionCode code, String message) {
        super(message);
        this.code = code;
    }

    public AppException(ExceptionCode code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public AppException(ExceptionCode code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    public AppException(ExceptionCode code, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

    @Override
    public String getMessage() {
        return code.getMessage() + ":错误码：【" + code.getCode() + "】" + super.getMessage();
    }
}
